import { ChangeDetectorRef, Component, Input, OnChanges, OnInit, SimpleChanges } from '@angular/core';
import { DictDataService } from '../../pages/system-setting/dict/service/dict-data.service';

@Component({
    selector: 'app-dict-label',
    templateUrl: './index.html',
    styleUrls: ['./index.scss']
})
export class DictLabelComponent implements OnInit ,OnChanges{
    @Input()
    dictValue: string="";
    @Input() dictKey :string;
    labelCase: Map<any, any> = new Map();
    colorCase:Map<string, string>=  new Map<string, string>([
        [
            'primary', 'green'
        ],
        [
            'info', 'blue'
        ],
        [
            'danger', 'red'
        ],
        [
            'warning', 'yellow'
        ]
    ])
    constructor(private dictDataService: DictDataService, private _changeDetectorRef: ChangeDetectorRef) {}

    ngOnInit() {
        this.dictDataService.getDictValue(this.dictKey).subscribe(res => {
            if (res.code == 200){
                res.data.forEach(( item: any) => {
                    this.labelCase.set(item.dictValue, { tag: item.dictLabel, listClass : item.listClass} as any);
                })
                console.log(this.labelCase)
            }
        })
    }

    ngOnChanges(changes: SimpleChanges): void {
    }

}
